<?php

namespace business\company\repositories;

use yii\base\InvalidConfigException;

class FhSupplierMulitDetailRepository
{
    /**
     * 通过时间区间获取供应商ID列表
     * @param string $startDate 开始时间
     * @param string $endDate
     * @return array 供应商ID列表
     * @throws InvalidConfigException
     */
    public function getSupplierIdsByTimeSlot($startDate, $endDate)
    {
        $connection = \Yii::$app->get('db');
        $sql = "SELECT
            uid 
        FROM
            `sourcing_meeting`.`sm_activity`
        WHERE
            activity_year = '2022'
            AND `is_deleted` = 0";
        $activityUid =  $connection->createCommand($sql)
            ->queryScalar();
        if ($activityUid){
            $sql = "SELECT
        b.supplier_id 
    FROM
        `sourcing_meeting`.`sm_supplier_mulit_detail` a
        JOIN `sourcing_meeting`.`sm_supplier` b ON b.uid = a.sm_supplier_id 
    WHERE a.activity_uid = :activity_uid and (( a.`created_at` >= :startDate AND a.`created_at` <= :endDate ) 
        OR ( a.`updated_at` >= :startDate AND a.`updated_at` <= :endDate ))
    GROUP BY
        b.supplier_id";
            return $connection->createCommand($sql)
                ->bindValue(':activity_uid', $activityUid)
                ->bindValue(':startDate', $startDate)
                ->bindValue(':endDate', $endDate)
                ->queryColumn();
        } else{
            return [];
        }

    }
}
